package com.example.passport.mapper;

import com.example.common.dto.Pagination;
import com.example.front.dto.BoxSearchDto;
import com.example.front.entity.Equipment;
import com.example.passport.dto.WxUserDto;
import com.example.passport.entity.User;
import com.example.passport.entity.WxUser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface WxUserMapper {

    @Select("<script>" +
            "SELECT count(*) FROM `wx_user` " +
            "<where>" +
            "<if test='condition.id!=null'> AND `id`=#{condition.id}</if>" +
            "<if test='condition.name!=null'> AND `name` LIKE CONCAT('%',#{condition.name},'%')</if>" +
            "<if test='condition.userid!=null'> AND `userid` LIKE CONCAT('%',#{condition.userid},'%') </if>" +
            " AND `tenant_id`=#{condition.tenantId} " +
            "</where> AND `status`!=" + User.STATUS_DELETE +
            "</script>")
    long count(@Param("condition") WxUserDto wxUserDto);

    @Select("<script>" +
            "select * from `wx_user`" +
            " <where>" +
            "<if test='wxUserDto.name!=null'> AND `name`=#{wxUserDto.name}</if>"+
            "<if test='wxUserDto.tenantId!=null'> AND `tenant_id`=#{wxUserDto.tenantId}</if>"+
            "<if test='wxUserDto.userid!=null'> AND `userid`=#{wxUserDto.userid}</if>"+
            "</where> AND `status`!=" + User.STATUS_DELETE +
            "</script>")
    WxUserDto findBy(@Param("wxUserDto") WxUserDto wxUserDto);

    @Select("<script>" +
            "SELECT * FROM `wx_user`" +
            "<where>" +
            "<if test='condition.id!=null'> AND `id`=#{condition.id}</if>" +
            "<if test='condition.name!=null'> AND `name` LIKE CONCAT('%',#{condition.name},'%')</if>" +
            "<if test='condition.tenantId!=null'> AND `tenant_id`=#{condition.tenantId}</if>" +
            "<if test='condition.userid!=null'> AND `userid` LIKE CONCAT('%',#{condition.userid},'%') </if>" +
            " AND `tenant_id`=#{condition.tenantId} " +
            "</where> AND `status`!=" + User.STATUS_DELETE +
            " ORDER BY `id` DESC " +
            "<if test='pagination.limit!=0'> LIMIT #{pagination.offset}, #{pagination.limit}</if>" +
            "</script>")
    List<WxUserDto> list(@Param("condition") WxUserDto wxUserDto, @Param("pagination") Pagination pagination);

    @Insert("INSERT INTO `wx_user`" +
            " (`name`,`tenant_id`,`userid`,`mobile`,`email`,`biz_mail`,`status`) VALUES" +
            " (#{wxUserDto.name}, #{wxUserDto.tenantId}, #{wxUserDto.userid}," +
            "#{wxUserDto.mobile},#{wxUserDto.email},#{wxUserDto.bizMail},#{wxUserDto.status})")
    int add(@Param("wxUserDto") WxUserDto wxUserDto);


}
